Rails.application.routes.draw do

  mount ChinaCity::Engine => '/china_city'

  root "home#index"

  get "get_baidu_ads" => 'home#get_baidu_ads'
  get "get_baidu_ads_for_mobile" => 'home#get_baidu_ads_for_mobile'
  get 'floor' => 'home#get_floor'

  #get 'demo' => 'home#demo'
  get 'sign_up' => 'users#new'
  get 'sign_in' => 'sessions#new', as: :sign_in
  get 'logout' => 'sessions#destroy'

  get 'password_reset' => 'password_reset#new'
  post 'password_reset' => 'password_reset#create'

  get '/auth/:provider/callback', to: 'sessions#third_party_create'

  #baidu editor
  post 'editor/upload_image' => 'baidu_editor#upload_image'

  %W{agreement order payment service brand culture core case contact outlets join service_outlets get_service_outlets customer_service}.each do |key|
    get "#{key}.html" => "abouts##{key}"
  end

  resources :sms, only: [:create]

  resources :roles
  resources :promotions
  resources :join_records, only: [:create]
  resources :sale_records, only: [:create]

  resources :wiki, :only => [:index, :show]

  resources :product_images
  resources :carts, only: [:index, :create, :update, :destroy] do
    collection do
      get :get_data
      post :batch_destroy
    end
  end
  resources :categories
  resources :payments, only: [] do
    collection do
      get :generate_pay
      get :callback
      get :get_charge
    end
  end
  resources :orders do
    member do
      post :create_contract_img
      get :callback
    end
  end
  resources :products do
    member do
      get :get_related_products
    end
  end
  resources :product_cases, only: [:index]
  resources :users
  resources :search, only: [] do
    collection do
      get :suggest
      get :query
    end
  end

  resources :sessions, :only => [:new, :create, :destroy]
  resources :reserves, :only => [:new, :create]
  resources :designers, :except => [:destroy] do
    collection do
      get :get_designers
      #get :community
      #get :activities
      #get :activity
    end
    resources :design_cases
  end

  resources :design_promotions, only: [:index, :show]

  resources :captcha, :only => [] do
    collection do
      get :get_data
    end
  end

  namespace :dashboard do
    resources :reserves, :only => [:show]
    resources :order_contracts, only: [:create]
    resources :orders, only: [:index, :show]
    resources :avatars, :only => [:update]
    resources :design_case_attachments, :only => [:update]
    resources :addresses, only: [:index, :new, :edit, :destroy, :create] do
      member do
        put :set_default_address
      end
      collection do
        get :all_province
      end
    end

    resources :invoices do
      member do
        put :set_default_invoice
      end
      collection do
        post :make_invoice
      end
    end

    resources :order_contracts, :only => [:create, :destroy]
    resources :designers, only: [:index] do
      collection do
        resources :design_cases
      end
    end
  end

  namespace :admin do
    root to: "home#index"
    resources :sale_records do
      member do
        get :change_state
      end
    end
    resources :join_records do
      member do
        get :change_state
      end
    end
    resources :channels
    resources :brands
    resources :categories
    resources :product_signs
    resources :specs
    resources :survey_fees
    resources :users, only: [:index]
    resources :service_networks
    resources :designer_promotions
    resources :floors
    resources :product_cases do
      resources :product_case_attachments, only: [:index, :create, :destroy, :update]
    end
    resources :orders, only: [:index, :show] do
      collection do
        get :search_master
        get :search_source
        post :create_api_order
        put :update_api_order_no
        get :edit_total_amount
        put :update_total_amount
        post :complete_order
      end
    end
    resources :addresses, only: [:edit, :update]
    resources :wiki
    resources :wiki_categories
    resources :roles, only: [:index]
    resources :reserves, only: [:index, :show]
    resources :promotions do
      member do
        put :enable_or_disable
      end
    end

    resources :sales_promotions do
      member do
        put :enable_or_disable
      end
    end

    resources :products do
      collection do
        get :get_data
        post :enable_top_or_disable_top
        post :set_on_or_off
      end
      resources :product_images, only: [:index, :create, :destroy, :update]
    end

  end

  api_for '/apidoc'

  namespace :api do
    namespace :v1 do
      resources :orders, only: [] do
        collection do
          post :log_cgj_result
        end
      end
    end
  end

end
